package com.searching.config;

import lombok.Getter;

import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.EventListener;
import java.util.HashSet;
import java.util.Set;

@Getter
public class searching_Config {

    private static volatile  searching_Config config;

    //索引的路径
    private Set<String> includePath = new HashSet<>();
    //排除的索引路径
    private Set<String> excludePath = new HashSet<>();
    //TODO 可配置的参数会在这里出现


    public static searching_Config getInstance() {
        if(config == null) {
            synchronized (searching_Config.class) {
                if(config == null) {
                    config = new searching_Config();
                    //遍历的目录
                    FileSystem fileSystem = FileSystems.getDefault();
                    Iterable<Path> iterable = fileSystem.getRootDirectories();
                    //这句话意思
                    iterable.forEach(path-> config.includePath.add(path.toString()) );
                    //排除的目录
                    String osname = System.getProperty("os.name");
                    if(osname.startsWith("Windows")) {
                        config.getExcludePath().add("C:\\Windows");
                        config.getExcludePath().add("C:\\Program Files(x86)");
                        config.getExcludePath().add("C:\\Program Files");
                        config.getExcludePath().add("C:\\ProgramData");
                    }else {
                        config.getExcludePath().add("/tmp");
                        config.getExcludePath().add("/etc");
                        config.getExcludePath().add("/root");
                    }

                }
            }
        }
        return config;
    }

    public static void main(String[] args) {
        searching_Config config = searching_Config.getInstance();
        System.out.println(config.getIncludePath());
        System.out.println(config.getExcludePath());
    }

}
